package bma.common.hibernate;

import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;

import bma.common.langutil.core.ClassUtil;

public class BMASessionFactoryBean extends LocalSessionFactoryBean {

	private String[] mappingClasses;

	public BMASessionFactoryBean() {
		super();
	}

	public String[] getMappingClasses() {
		return mappingClasses;
	}

	public void setMappingClasses(String[] mappingClasses) {
		this.mappingClasses = mappingClasses;
	}

	@Override
	protected void postProcessConfiguration(Configuration config)
			throws HibernateException {
		if (mappingClasses != null) {
			for (String n : mappingClasses) {
				Class<?> cls;
				try {
					cls = ClassUtil.forName(n);
				} catch (ClassNotFoundException e) {
					throw new HibernateException(e.getMessage());
				}
				config.addAnnotatedClass(cls);
			}
		}
		super.postProcessConfiguration(config);
	}
}
